﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;


namespace FYPDemo
{
    public partial class Member_Sales_Report : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string paidFrom = "";
            string paidTo = "";
            string name = txtMember.Text;

            if((txtPaidFrom.Text) != "")
                paidFrom = txtPaidFrom.Text + " 00:00:00.000";

            if((txtPaidTo.Text) != "")
                paidTo = txtPaidTo.Text + " 23:59:59.999";

            DataTable dt = new DataTable();

            dt = BackOffice_Report.MemberSalesReport1(name, paidFrom, paidTo);

            MemberSalesReport_Grid.DataSource = dt;
            MemberSalesReport_Grid.DataBind();

            lblMemberCount.Text = dt.Rows.Count.ToString();
        }

        protected void MemberSales_Command(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "OrderID")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                string orderid = MemberSalesReport_Grid.DataKeys[index].Values["OrderID"].ToString();

                Response.Redirect("Member_Sales_Report2.aspx?orderID=" + orderid);
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;

            string year = dt.Year + "";
            string month = dt.Month + "";
            string day = dt.Day + "";
            string fileName = "Member_Sales_Report" + year + month + day;
            GridViewExportUtil.Export(fileName + ".xls", this.MemberSalesReport_Grid);
        }
    }
}